#include "test_parser.h"

// -------------------------------------------------------------------------------------------------

using namespace sea;
using namespace std;

// -------------------------------------------------------------------------------------------------

ACT_IMPL( TestParser, init ) 
{  
    SEA_UNUSED_PARAM( );
}

// -------------------------------------------------------------------------------------------------

ACT_IMPL( TestParser, ParseBinarySm ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, readString ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, getLiteral ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, createStateMachine ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, storeExecMode ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, createState ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, storeHeartBeatInterval ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, storeHeartBeats ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, createEventRecord ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, storeEvent ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, storeAction ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, storeNextState ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, endOfState ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, complete ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, error ) {  SEA_UNUSED_PARAM( ); }
ACT_IMPL( TestParser, resolveNextStates )  {  SEA_UNUSED_PARAM( ); }

// -------------------------------------------------------------------------------------------------

#if defined( STATIC_META_DATA_ENABLED )

EVENT_INT_IMPL( TestParser, Ev_Int_InitOk );
EVENT_INT_IMPL( TestParser, Ev_Int_InitBinaryOk );
EVENT_INT_IMPL( TestParser, Ev_Int_InitFailed );
EVENT_INT_IMPL( TestParser, Ev_Int_ParseError );
EVENT_INT_IMPL( TestParser, Ev_Int_Eol );
EVENT_INT_IMPL( TestParser, Ev_Int_Eof );
EVENT_INT_IMPL( TestParser, Ev_Int_NotEmptyString );
EVENT_INT_IMPL( TestParser, Ev_Int_GotNumber );
EVENT_INT_IMPL( TestParser, Ev_Int_GotName );
EVENT_INT_IMPL( TestParser, Ev_Int_GotOpenBracket );
EVENT_INT_IMPL( TestParser, Ev_Int_GotCloseBracket );
EVENT_INT_IMPL( TestParser, Ev_Int_ResolveOk );
EVENT_INT_IMPL( TestParser, Ev_Int_ParseWarning );

#endif

// -------------------------------------------------------------------------------------------------

int binSm[ ] = 
#if 1
{
    0, 0, 0,            // Reserved

    2,                  // EXM :: SYNC
    14,                 // NOS
    1,                  // ISI
        // 0. Exception
        0, 0, 9,        // HBI HBN NOR
            4, 15, 13,  // EAS
            5, 15, 13,
            6, 15, 13,
            7, 15, 13,
            8, 15, 13,
            9, 15, 13,
           10, 15, 13,
            3, 15, 13,
           12, 15, -1,
        // 1. SmName
        0, 0, 8,
           -3,  0, -1,
            0,  2, -1,
            1, -1, 13,
            2, 15, 13,
            4,  2, -1,
            6,  3, -1,
            8,  4,  2,
            5, -1, 13,
        // 2. ExecMode
        0, 0, 5,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            8,  5,  3,
            9, -1,  4,
        // 3. AtSmEntry
        0, 0, 4,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            9, -1,  4,
        // 4. StateName
        0, 0, 5,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            8,  6,  5,
           10, -1, 12,
        // 5. StateHeartBeatInterval
        0, 0, 6,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            7,  7,  6,
            9,  7, -1,
            9,  8,  8,
        // 6. StateHeartBeats
        0, 0, 5,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            7,  8,  7,
            9,  8,  8,
        // 7. AtStateEntry
        0, 0, 4,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            9, -1,  8,
        // 8. Event
        0, 0, 6,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            8,  9, -1,
            8, 10,  9,
           10, -1,  4,
        // 9. Action
        0, 0, 4,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            8, 11, 10,
        // 10. NextState
        0, 0, 4,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

            8, 12, 11,
        // 11. AtStateExit
        0, 0, 6,
           -3,  3, -1,
            4,  2, -1,
            6,  3, -1,

           10, 13,  4,
            8,  9, -1,
            8, 10,  9,
        // 12. AtSmExit
        0, 0, 2,
           -3,  16, -1,
           11,  14, 13,
        // 13. Exit
        0, 0, 1,
           -3, -2, -1
};
#endif

// -------------------------------------------------------------------------------------------------

void test_state_machine_parser( )
{
    {
        #include "../src/sea_parser.hxx"
#if defined( SEA_OS_LINUX )
        const char* file = "../tests/test_parser.txt";
#else
        const char* file = "tests\\test_parser.txt";
#endif
        TestParser the_bin;
        TestParser the_string;
        TestParser the_file;

        // eBinary
        the_bin.create( 0, binSm );
        the_bin.print( );

        the_bin.create( 1, binSm );
        the_bin.print( );

        the_bin.create( 2, binSm);
        the_bin.print( );

        // eString
        the_string.create( 3, the_source );
        the_string.print( );

        // eString
        the_string.create( 4, the_source );
        the_string.print( );

        // eFile
        the_file.create( 5, file, StateMachine::eFile );
        the_file.print( );

        // eFile
        the_file.create( 6, file, StateMachine::eFile );
        the_file.print( );
    }
    Engine::terminate( );
}

// -------------------------------------------------------------------------------------------------
